<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<html>
<head>
	<meta charset="UTF-8">
	<title>入库详情</title>
	<meta name="viewport" content="width=360,height=640,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
	<link rel="stylesheet" href="<%=basePath%>/css/pda/loginPda.css" />
	<link rel="stylesheet" href="<%=basePath%>/css/pda/pop.css" />
	<link rel="stylesheet" href="<%=basePath%>/css/pda/jquery.spinner.css" />
	<link href="<%=basePath%>/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
</head>
<style>
	body, html{
		width:100%;height:100%;
	}
	#query{
	border:none;
	color:#fff;
	background:#1ba2e3;
		height:36px;
		padding:0 5px;
		border-radius:0 4px 4px 0;
		position:relative;
		left:-2px;
	}
	#purchaseOrderId{
		border:1px solid #ddd;
		height:36px;
		border-radius:4px 0 0 4px;
	}
	.btnGroup{
		margin-top:40px;
	}
	.btnGroup input{
		display: inline-block;
		width: 80px;
		height: 30px;
		line-height: 30px;
		text-align: center;
		border-radius: 6px;
		bordeR: none;
		color: #fff;
		font-size: 16px;
		margin: 0 10px;
	}
	.btnGroup input:nth-child(1) {
		background: #1ba2e3;
	}
	.btnGroup input:nth-child(2) {
		background: #f5af55;
	}
</style>
<body>
<div class="pdaHead">
	<a href="<%=basePath%>/web/invInputHead/goSupplyMaterial"><img src="<%=basePath%>img/pda/arrow_back.png" alt="" /></a>
	<span>商品入库</span>
</div>
<form id="form" action="<%=basePath%>/web/invInputPda/save" method="post">
	<input type="hidden" name="supplyMaterialDetailId" id="supplyMaterialDetailId" value="${requestScope.supplyMaterialDetail.id}">
	<input type="hidden" name="purchase_order_id" id="purchase_order_id" value="${requestScope.supplyMaterial.purchase_order_id}">
	<input type="hidden" name="supplyMaterialId" id="supplyMaterialId" value="${requestScope.supplyMaterial.id}">
	<div class="pdaContent">

		<div class="listInfo">
			<span>商品编码：</span>
			<span id="material_code">${requestScope.supplyMaterialDetail.material_code}</span>
		</div>
		<div class="listInfo">
			<span>商品名称：</span>
			<span>${requestScope.supplyMaterialDetail.material_name}</span>
		</div>
		<div class="listInfo">
			<span>单位：</span>
			<span id="standard_unit">${requestScope.supplyMaterialDetail.standard}</span>
		</div>
		<div class="listInfo">
			<span>规格：</span>
			<span id="standard">${requestScope.supplyMaterialDetail.standard_unit}</span>
		</div>
		<div class="listInfo">
			<span>单价：</span>
			<span id="price">${requestScope.supplyMaterialDetail.price}</span>
		</div>
		<div class="listInfo">
			<span>应入库量：</span>
			<span id="num">${requestScope.supplyMaterialDetail.num}</span>
		</div>
		<div class="listInfo">
			<span>实入库量：</span>
			<input type="text" class="spinnerExample" id="numReally" name="numReally" value="0"/>
		</div>
		<div class="listInfo">
			<span>损耗值：</span>
			<input type="text" class="spinnerExample" id="sunhao" name="sunhao" value="0"/>
		</div>
		<div class="listInfo">
			<span>损耗原因：</span>
			<input type="text"  id="loss_memo" name="loss_memo" value="0"/>
		</div>
		<div class="listInfo">
			<span>操作员：</span>
			<span>${staffInfo.staffName}</span>
		</div>
		<div class="listInfo">
			<span>所属单位：</span>
			<span>${staffInfo.companyName}</span>
		</div>
		<div class="listInfo">
			<span>所属部门：</span>
			<span>${staffInfo.departmentName}</span>
		</div>
		<div class="listInfo">
			<span>所属仓库：</span>
			<select id="warehouse" name="warehouse" class="warehouse">
				<c:forEach items="${requestScope.warehouseMap}" var="warehouse">
					<option value="${warehouse.key}" address="${warehouse.value.warehouseAddress}">${warehouse.value.warehouseName}</option>
				</c:forEach>
			</select>
		</div>
		<div class="listInfo">
			<span>备注：</span>
			<span><textarea name="desc" id="desc" rows="3" cols="" value="${requestScope.supplyMaterialDetail.material_name}">请输入备注</textarea></span>
		</div>
		<div class="btnGroup btnGroup1">
			<input type="button"  id="checkSubmit" value="保存">
			<input type="button"  id="backup" value="返回">
		</div>
	</div>
</form>
</body>
<script src="<%=basePath%>/css/bootstrap-3.3.7/js/jquery-2.1.4.min.js" type="text/javascript" charset="utf-8"></script>
<script src="<%=basePath%>/css/bootstrap-3.3.7/js/bootstrap.js" type="text/javascript" charset="utf-8"></script>
<script src="<%=basePath%>/js/jquery.spinner.js" type="text/javascript" charset="utf-8"></script>
<script src="<%=basePath%>js/plugins/sweetalert/sweetalert.min.js"></script>
<script src="<%=basePath%>js/redragon.js" type="text/javascript" charset="utf-8"></script>
<script>

    jQuery(document).ready(function($){
        $('.spinnerExample').spinner({});
        //open popup
        $('.cd-popup-trigger').on('click', function(event){
            event.preventDefault();
            $('.cd-popup').addClass('is-visible');
        });

        //close popup
        $('.cd-popup').on('click', function(event){
            if( $(event.target).is('.cd-popup-close') || $(event.target).is('.cd-popup') ) {
                event.preventDefault();
                $(this).removeClass('is-visible');
            }
        });
        //close popup when clicking the esc keyboard button
        $(document).keyup(function(event){
            if(event.which=='27'){
                $('.cd-popup').removeClass('is-visible');
            }
        });
    });
</script>
<script>
    function querySupply_Mterial(){
        if($("#purchaseOrderId").val()==""){
            $(".innerText").html("请输入供货单编号!");
            $("#purchaseOrderId").focus();
            return;
		}
        let sub = {};
        sub.supplyMaterialId = $("#purchaseOrderId").val();
        $.ajax({
            url : "<%=basePath%>/web/invInputPda/getSupplyMaterialData",
            contentType : "application/json",
            dataType : 'json',
            data : JSON.stringify(sub),
            type:'post',
            async : false,
            success: function (data) {
                if(data.code == 0) {
                    $("#purchaseOrderId").html(data.supplyMaterial.purchase_order_id);
                    $("#vendorName").html(data.supplyMaterial.vendor_name);
                    $("#price").html(fmoney(data.supplyMaterial.price,2)+"元");
                    $("#sendDate").html(data.supplyMaterial.send_time);
                    var html="";
                    if(data.supplyMaterialDetailList.length>0){
						for(var i=0;i<data.supplyMaterialDetailList.length;i++){
							html+="<tr>"
							 html+="<td>"+i+"</td>"
							 html+="<td>"+data.supplyMaterialDetailList[i]["material_code"]+"</td>"
							 html+="<td>"+data.supplyMaterialDetailList[i]["material_code"]+"</td>"
							 html+="<td>"+data.supplyMaterialDetailList[i]["num"]+"</td>"
							 html+="<td class='ruku'><span>入库</span></td>"
							 html+="</tr>"
						}
                        $("#materialTable").append(html);
					}
                } else {
                   $(".innerText").html(data.msg);
                }
            }
        });
	}
    //格式化金额
    function fmoney(s, n)
    {
        n = n > 0 && n <= 20 ? n : 2;
        s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";//更改这里n数也可确定要保留的小数位
        var l = s.split(".")[0].split("").reverse(),
            r = s.split(".")[1];
        t = "";
        for(i = 0; i < l.length; i++ )
        {
            t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");
        }
        return t.split("").reverse().join("") + "." + r.substring(0,2);//保留2位小数  如果要改动 把substring 最后一位数改动就可
    }
    $("#checkSubmit").click(function () {
        //计算损耗比率
        var num=$("#num").html();
        var numReally=$("#numReally").val();
        var sunhao=$("#sunhao").val();
        //redragonJS.alert("====");
        if("0"==numReally){
            redragonJS.alert("实际入库量不能为0!");
            $("#numReally").focus();
            return false;
        }
        if("0"==sunhao){
            redragonJS.alert("损耗值不能为0!");
            $("#sunhao").focus();
            return false;
        }
        //计算偏差率如果大于不让保存给出提示
        //redragonJS.alert(Math.abs((1-numReally/num)));
        // if(Math.abs((1-numReally/num))>sunhao){
        //     redragonJS.alert("损耗率不能大于"+sunhao);
        //     $("#sunhao").focus();
        //     return false;
        // }
        $("#form").submit()
    })
    $("#backup").click(function () {
        javascript:history.back(-1);
	})

</script>
</html>